﻿package physic.elements
{
	import events.PlateformeEvent;
	import flash.display.MovieClip;
	import drawer.events.DrawEvent;
	import fab.Utils;
	import flash.display.DisplayObject;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.geom.Matrix;
	import physic.Obstacle;
	
	import fab.geom.*;
	import bipede.membres.Pied;
	
	public class Ascenceur extends MovieClip
	{
		private var vitesse:Number = .005;
		private var parcours:Segment = new Segment(new Point(450, 280), new Point(100, 350));
		private var avancement:Number=0;
		private var sens:Boolean=true;
		
		public function Ascenceur()
		{
			
			
			
			//demarre();
		}
		private function demarre():void 
		{
			addEventListener( Event.ENTER_FRAME, _frame );
		}
		private function arrete():void 
		{
			removeEventListener( Event.ENTER_FRAME, _frame );
		}
		private function _frame(e:Event):void 
		{
			avancement = avancement + (sens?1: -1) * vitesse;
			if ( avancement > 1 || avancement < 0 )
			{
				sens = !sens;
			}
			place = parcours.pointAt( avancement );
		}
		public function set place(p:Point):void
		{
			var deplacement:Point = p.subtract( place );
			
			//x = int( p.x );
			//y = int( p.y );	
			x = ( p.x );
			y = ( p.y );	
			
			//TODO
			// ici p1 et p2 ne bougent pas, mais si l'ascenceur se déforme...
			dispatchEvent( new PlateformeEvent( PlateformeEvent.UPDATE, deplacement ) );// new Point( p1.x, p1.y ), new Point( p2.x, p2.y ) ) );
		}
		public function get place():Point
		{
			return new Point( x, y );
		}		
		override public function toString():String
		{
			return "Ascenceur : " + name;
		}			
	}	
}